<?php

use App\Models\Banner;

return [
    'title'   => '社区公告',
    'heading' => '社区公告',
    'single'  => '社区公告',
    'model'   => Banner::class,

    'query_filter' => function ($query) {
        $query->where('position', 'announcements');
        if (!Input::get('sortOptions')) {
            $query->orderBy('order', 'ASC');
        }
    },

    'columns' => [
        'id' => [
            'title' => 'ID',
        ],
        'title' => [
            'title'  => '标题',
            'output' => function ($value, $model) {
                return $model->link ? "<a href='{$model->link}' target='_blank'>{$value}</a>" : $value;
            },
        ],
        'target' => [
            'title'  => '打开方式',
            'output' => function ($value) {
                return $value == '_blank' ? '新窗口打开' : '本站打开';
            },
        ],
        'start_date' => [
            'title' => '开始时间',
            'type' => 'datetime'
        ],
        'end_date' => [
            'title' => '结束时间',
            'type' => 'datetime'
        ],
        'order' => [
            'title'    => '排序（按小到大排序）',
            'sortable' => false,
        ],
        'operation' => [
            'title'  => '管理',
            'output' => function ($value) {
                return $value;
            },
            'sortable' => false,
        ],
    ],
    'edit_fields' => [
        'position' => [
            'title'    => '位置',
            'visible'  => false,
            'value'    => 'announcements',
        ],
        'title' => [
            'title' => '标题',
        ],
        'target' => [
            'title'    => '打开方式',
            'type'     => 'enum',
            'options'  => [
                '_blank' => '新窗口打开',
                '_self'  => '本站打开',
            ],
            'value' => '_blank',
        ],
        'link' => [
            'title' => '链接地址',
        ],
        'start_date' => [
            'title' => '开始时间',
            'type' => 'datetime'
        ],
        'end_date' => [
            'title' => '结束时间',
            'type' => 'datetime'
        ],
        'order' => [
            'title' => '排序（按小到大排序）',
            'type'  => 'number',
            'value' => 0,
        ],
    ],
    'filters' => [
        'id' => [
            'title' => 'ID',
        ],
        'title' => [
            'title' => '标题',
        ],
        'order' => [
            'title' => '排序（按小到大排序）',
            'type'  => 'number',
        ],
    ],
];
